package com.zh.stargraph2.core.controller;

import com.zh.stargraph2.core.dto.common.Result;
import com.zh.stargraph2.core.dto.request.UserLoginReqDTO;
import com.zh.stargraph2.core.dto.respone.UserLoginResDTO;
import com.zh.stargraph2.core.service.UserService;
import org.apache.coyote.BadRequestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/1.0/user")
public class UserController {

    @Autowired
    private UserService userService;


    @PostMapping("/login")
    public Result<UserLoginResDTO> login(@RequestBody @Validated UserLoginReqDTO userLoginReqDTO) throws BadRequestException{
        return Result.ok(userService.loginByPassword(userLoginReqDTO));
    }
}
